﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;

using ChinaSoft.Model;
using ChinaSoft.BLL;

namespace MidSoft.Sys.Department
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int OrganizeId = (ChinaSoft.Common.Input.SetInt(Request.Params["id"]));
                    GetOrganizeName(OrganizeId);
                }
            }
        }
        private void GetOrganizeName(int organizeid)
        {
            BLL_tb_MidSoft_Organize bllOrganize = new BLL_tb_MidSoft_Organize();
            Model_tb_MidSoft_Organize modelOrganize = bllOrganize.GetModel(organizeid);
            if (modelOrganize != null)
            {
                lblOrganize.Text = modelOrganize.OrganizeName;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtDepartMentName.Text.Trim().Length == 0)
            {
                strErr += "部门名称不能为空！\\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int OrganizeId =0;
            if (!string.IsNullOrEmpty(Request.Params["id"]))
                OrganizeId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            string DepartMentName = this.txtDepartMentName.Text;
            string DepartMentNumber = this.txtDepartMentNumber.Text;
            DateTime CreateTime = DateTime.Now;

            int CreateUserId = 0;
            if (Session["currentUserID"] != null && Session["currentUserID"].ToString() != "")
                CreateUserId = ChinaSoft.Common.Input.SetInt(Session["currentUserID"]);
            #region 添加
            ChinaSoft.Model.Model_tb_MidSoft_DepartMent model = new ChinaSoft.Model.Model_tb_MidSoft_DepartMent();
            model.OrganizeId = OrganizeId;
            model.DepartMentName = DepartMentName;
            model.DepartMentNumber = DepartMentNumber;
            model.CreateTime = CreateTime;
            model.CreateUserId = CreateUserId;

            ChinaSoft.BLL.BLL_tb_MidSoft_DepartMent bll = new ChinaSoft.BLL.BLL_tb_MidSoft_DepartMent();
            int departmentId=bll.Add(model);
            #endregion

            #region 添加日志
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.userAccount = "";
            if (Session["UserAccount"] != null && Session["UserAccount"].ToString() != "")
                modelLog.userAccount = Session["UserAccount"].ToString();
            modelLog.userName = "";
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
                modelLog.userName = Session["UserName"].ToString();
            modelLog.description = "甲方信息添加,ID=" + departmentId + ",DepartMentName=" + DepartMentName;
            modelLog.LogType = 1;
            modelLog.CreateTime = DateTime.Now;
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}